#
# Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
#

# -*- mode: python; -*-

import sys

Import('BuildEnv')

env = BuildEnv.Clone()

except_env = BuildEnv.Clone()
except_env.Append(CPPPATH = env['TOP'])
except_env.CppEnableExceptions()

timer_env = BuildEnv.Clone()
timer_env.AppendUnique(CCFLAGS='-DBOOST_CHRONO_HEADER_ONLY')

TaskInfoSandeshGenFiles = env.SandeshGenCpp('sandesh/task.sandesh')
TaskInfoSandeshGenSrcs = env.ExtractCpp(TaskInfoSandeshGenFiles)
taskinfo_sandesh_files_ = []
for src in TaskInfoSandeshGenSrcs:
    objname = src.replace('.cpp', '.o')
    obj = env.Object(objname, src)
    taskinfo_sandesh_files_.append(obj)

CpuInfoSandeshGenFiles = env.SandeshGenCpp('sandesh/cpuinfo.sandesh')
CpuInfoSandeshGenSrcs = env.ExtractCpp(CpuInfoSandeshGenFiles)

cpuinfo_sandesh_files_ = []
for src in CpuInfoSandeshGenSrcs:
    objname = src.replace('.cpp', '.o')
    obj = env.Object(objname, src)
    cpuinfo_sandesh_files_.append(obj)

libcpuinfo = env.Library('cpuinfo', ['cpuinfo_common.cc', 'linux/cpuinfo.cc'] + cpuinfo_sandesh_files_)

task = except_env.Object('task.o', 'task.cc')
timer = timer_env.Object('timer.o', 'timer.cc')
task_monitor = timer_env.Object('task_monitor.o', 'task_monitor.cc')

ProcessInfoSandeshGenFiles = env.SandeshGenCpp('sandesh/process_info.sandesh')
ProcessInfoSandeshGenSrcs = env.ExtractCpp(ProcessInfoSandeshGenFiles)

libprocessinfo = env.Library('process_info',
                          ['connection_info.cc', 'feature_flags.cc'] +
                          ProcessInfoSandeshGenSrcs)

NodeInfoSandeshGenFiles = env.SandeshGenCpp('sandesh/nodeinfo.sandesh')
NodeInfoSandeshGenSrcs = env.ExtractCpp(NodeInfoSandeshGenFiles)
libnodeinfo = env.Library('nodeinfo',
                          NodeInfoSandeshGenSrcs)

VersionInfoSandeshGenFiles = env.SandeshGenCpp('sandesh/version.sandesh')
VersionInfoSandeshGenSrcs = env.ExtractCpp(VersionInfoSandeshGenFiles)

# base
contrail_common_base_doc_files = []
base_doc_target = BuildEnv['TOP'] + '/base/sandesh/'
contrail_common_base_doc_files += BuildEnv.SandeshGenDoc('#src/contrail-common/base/sandesh/cpuinfo.sandesh', base_doc_target)
contrail_common_base_doc_files += BuildEnv.SandeshGenDoc('#src/contrail-common/base/sandesh/process_info.sandesh', base_doc_target)
BuildEnv['BASE_DOC_FILES'] = contrail_common_base_doc_files
Export('contrail_common_base_doc_files')

env.Append(CPPPATH = env['TOP'])
libbase_src = [
    VersionInfoSandeshGenSrcs +
    [
        'bgp_as_service_utils.cc',
        'contrail_ports.cc',
        'misc_utils.cc',
        'bitset.cc',
        'index_allocator.cc',
        'label_block.cc',
        'lifetime.cc',
        'logging.cc',
        'proto.cc',
        'watermark.cc',
        task,
        'task_annotations.cc',
        task_monitor,
        'task_sandesh.cc',
        'task_trigger.cc',
        'tdigest.c',
        timer,
        taskinfo_sandesh_files_,
        'address.cc',
        'address_util.cc',
    ]
]

libbase_src.append('backtrace.cc')

libbase = env.Library('base', libbase_src)
env.Requires(libbase, '#/build/lib/' + env['LIBPREFIX'] + 'log4cplus' + env['LIBSUFFIX'])

env.Requires(libbase, '#/build/include/boost')
env.Install(env['TOP_LIB'], libcpuinfo)
env.Install(env['TOP_LIB'], libprocessinfo)
env.Install(env['TOP_LIB'], libnodeinfo)
env.Install(env['TOP_LIB'], libbase)

env.SConscript('test/SConscript', exports='BuildEnv', duplicate = 0)
